package com.cloudz.iptv.bing;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.cloudz.iptv.R;
import com.cloudz.iptv.activity.BaseActivity;
import com.cloudz.iptv.api.v1.BingServiceApi;
import com.cloudz.iptv.utils.RetrofitUtils;
import com.cloudz.iptv.utils.SimplePreference;
import com.owen.widget.RoundFrameLayout;

import butterknife.BindView;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class BingErrorActivity extends BaseActivity
{

    @BindView(R.id.bing_btn_cs)
    RoundFrameLayout bing_btn_cs;

    @BindView(R.id.bing_btn_fh)
    RoundFrameLayout bing_btn_fh;

    @Override
    public int getLayoutId()
    {
        return R.layout.activity_bing_connect_server_error;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // 设置按钮监听
        bing_btn_cs.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                bingInit();
            }
        });

        // 返回
        bing_btn_fh.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                finish();
            }
        });
    }

    /**
     * 绑定初始化
     */
    private void bingInit()
    {


        String deviceId = SimplePreference.getDeviceId(BingErrorActivity.this);

        // 验证绑定情况
        BingServiceApi bingServiceApi = RetrofitUtils.getInstance().createApi(SimplePreference.getServerUrl(this), BingServiceApi.class);

        bingServiceApi.bindInit(deviceId).enqueue(new Callback<ResponseBody>()
        {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response)
            {

                int code = response.code();
                if (code == 200)
                {

                } else
                {
                    showToast("重试失败");
                }

            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t)
            {
                showToast("重试失败");
            }
        });

    }
}
